#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.base.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;

import static ${package}.enums.ErrorCodeEnum.SERVICE_EXCEPTION;
import static ${package}.enums.ErrorCodeEnum.SUCCESS;

/**
 * 接口返回数据格式
 *
 * @author scott
 * @email jeecgos@163.com
 * @date 2019年1月19日
 */
@Data
@Schema(description = "接口返回对象")
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 成功标志
     */
    @Schema(description = "成功标志")
    private boolean success = true;

    /**
     * 返回处理消息
     */
    @Schema(description = "返回处理消息")
    private String message = "操作成功！";

    /**
     * 返回代码
     */
    @Schema(description = "返回代码")
    private Integer code = 0;

    /**
     * 返回数据对象 data
     */
    @Schema(description = "返回数据对象")
    private T result;

    /**
     * 时间戳
     */
    @Schema(description = "时间戳")
    private long timestamp = System.currentTimeMillis();
    /**
     * 链路追踪id
     */
    @Schema(description = "链路追踪id")
    private String traceId;

    public Result() {

    }

    public Result<T> success(String message) {
        this.message = message;
        this.code = SUCCESS.getCode();
        this.success = true;
        return this;
    }


    public static <T> Result<T> OK() {
        Result<T> r = new Result<T>();
        r.setSuccess(true);
        r.setCode(SUCCESS.getCode());
        r.setMessage(SUCCESS.getDesc());
        return r;
    }

    public static <T> Result<T> OK(T data) {
        Result<T> r = new Result<T>();
        r.setSuccess(true);
        r.setCode(SUCCESS.getCode());
        r.setResult(data);
        return r;
    }

    public static <T> Result<T> OK(String msg, T data) {
        Result<T> r = new Result<T>();
        r.setSuccess(true);
        r.setCode(SUCCESS.getCode());
        r.setMessage(msg);
        r.setResult(data);
        return r;
    }

    public static Result<Object> error(String msg) {
        return error(SERVICE_EXCEPTION.getCode(), msg);
    }

    public static Result<Object> error(long code, String msg) {
        Result<Object> r = new Result<Object>();
        r.setCode((int) code);
        r.setMessage(msg);
        r.setSuccess(false);
        return r;
    }



}